import java.net.InetAddress;
import java.net.UnknownHostException;

public class name {
    public static void main(String[] args) {
        try {
            //获取自己电脑的IP地址
            InetAddress ip1 = InetAddress.getLocalHost();//getLocalHost()创建一个电脑对象
            System.out.println(ip1.getHostName());//getHostName()获取名字
            System.out.println(ip1.getHostAddress());//getHostAddress（）获取IP地址
            //获取网站的IP地址
            InetAddress ip2 =  InetAddress.getByName("www.baidu.com");//创建一个可获取网站的方法
            System.out.println(ip2.getHostName());
            System.out.println(ip2.getHostAddress());
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }


    }
}
